<template>
  <el-form v-if="autoCCWay=='byUsers'" style="margin-bottom: 10px;">
    <by-users ref="byUsers" :select-data="this.selectData" :cc-data="this.ccData"></by-users>
  </el-form>
  <el-form v-else-if="autoCCWay=='byRoles'" style="margin-bottom: 10px">
    <by-roles ref="byRoles" :select-data="this.selectData" :cc-data="this.ccData"></by-roles>
  </el-form>
  <el-form v-else-if="autoCCWay=='byPositions'" style="margin-bottom: 10px">
    <by-positions ref="byPositions" :select-data="this.selectData" :cc-data="this.ccData"></by-positions>
  </el-form>
</template>

<script>
import ByUsers from "@/views/flow/components/ccModel/byUsers";
import ByRoles from "@/views/flow/components/ccModel/byRoles";
import ByPositions from "@/views/flow/components/ccModel/byPositions";
import {getSelectData, saveOrSend} from "@/api/task/ccToUser";
export default {
  name: "ccDefault",
  components: {ByPositions, ByRoles, ByUsers},
  props:['autoCCWay','task_def_key','ccWay','proc_inst_id'],
  data(){
    return{
      //已选中的数据，配置时使用
      selectData:[],
      //已配置的数据，抄送时使用
      ccData:[],
      params: {
        data:[],
        task_key:this.task_def_key,
        autoCCWay:this.autoCCWay,
        ccWay:this.ccWay,
        proc_inst_id:this.proc_inst_id
      },
    }
  },
  created() {
    this.getList();
  },
  methods:{
    //加载数据
    getList(){
      getSelectData(this.params).then((res) => {
          if (res.error === 200) {
            this.selectData=res.result;
            this.ccData=[];
          }
          else {
            this.$message.error(`获取列表失败`);
          }
      });
    },
    //执行保存或发送
    handlerSave(){
      if(this.autoCCWay=='byUsers'){
        this.params.data=this.$refs.byUsers.handlerSave();
      }
      else if(this.autoCCWay=='byRoles'){
        this.params.data=this.$refs.byRoles.handlerSave();
      }
      else if(this.autoCCWay=='byPositions'){
        this.params.data=this.$refs.byPositions.handlerSave();
      }
      if(this.params.data==[]){
        this.$message.error(`没有选中数据`);
        return ;
      }
      saveOrSend(this.params).then((res) => {
        if (res.error === 200){
          return "设置成功";
        }
        else{
          this.$message.error(res.msg);
        }
      });
    },
  }
}
</script>

<style scoped>

</style>
